<?php
define('DATABASE','dealscombined');
require("/var/www/sandbox/dealscombined.co.uk/scripts/connect.php");

// Select DB
$db=mysql_select_db(DATABASE,$connect);
if(!$db) {
die('Can\'t use DATABASE : '.mysql_error());
}

if(isset($_POST['submit']) && !empty($_POST['category']) && !empty($_POST['keyword1']) && !empty($_POST['keyword2']) && !empty($_POST['keyword3'])){
	
	$categories = array();
	foreach($_POST['category'] as $check){
		
		$categories[] = $check;
	
	}
	
	$categories = implode(',', $categories);
	
	mysql_query("INSERT INTO mapping_targets SET category_ids ='$categories'");
	
	mysql_query("INSERT INTO mappings SET first_word ='". mysql_real_escape_string($_POST['keyword1']) ."'
			 ,second_word ='". mysql_real_escape_string($_POST['keyword2']) ."'
			 ,third_word ='". mysql_real_escape_string($_POST['keyword3']) ."'
			 ,fourth_word ='". mysql_real_escape_string($_POST['keyword4']) ."'
			 ,fifth_word ='". mysql_real_escape_string($_POST['keyword5']) ."'");
}
	header( "refresh:2;url=mapper.php");
	echo "Ruleset Mapped: If you are not redirected in 5 seconds, please click <a href='mapper.php'>here</a>.";

?>